package com.woniuxy.user.controller;

import com.woniuxy.commons.request.ResPage;
import com.woniuxy.commons.request.ResponseResult;
import com.woniuxy.user.entity.Role;
import com.woniuxy.user.service.RoleService;
import com.woniuxy.user.vo.RoleVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Resource
    private RoleService roleService;
    /**
     * 角色列表
     */
    @GetMapping("/getRoleList")
    public ResponseResult<ResPage<Role>> getRoleList(RoleVo roleVo) {
        return new ResponseResult<>(ResponseResult.OK, roleService.getRoleList(roleVo));
    }
    /**
     * 验证角色名称
     */
    @GetMapping("/checkName/{name}")
    public ResponseResult<Boolean> checkName(@PathVariable("name") String name) {
        return new ResponseResult<>(ResponseResult.OK, roleService.checkName(name));
    }
    /**
     * 添加角色
     */
    @PostMapping("/addRole")
    public ResponseResult<Boolean> addRole(@RequestBody Role role) {
        return new ResponseResult<>(ResponseResult.OK, roleService.addRole(role));
    }
    /**
     * 编辑角色
     */
    @PutMapping("/editRole")
    public ResponseResult<Boolean> editRole(@RequestBody Role role) {
        return new ResponseResult<>(ResponseResult.OK, roleService.editRole(role));
    }
    /**
     * 删除角色
     */
    @DeleteMapping("/deleteRole/{id}")
    public ResponseResult<Boolean> deleteRole(@PathVariable("id") Integer id) {
        return new ResponseResult<>(ResponseResult.OK, roleService.deleteRole(id));
    }
    /**
     * 获取除用户外其他权限
     */
    @GetMapping("/getRoleListForEmployee")
    public ResponseResult<List<Role>> getRoleListForEmployee() {
        return new ResponseResult<>(ResponseResult.OK, roleService.getRoleListForEmployee());
    }

}
